package com.fxp.project.jiuselu.web.models.userlog.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fxp.project.jiuselu.web.models.userlog.entity.UserLogBrowse;
import com.fxp.project.jiuselu.web.models.userlog.mapper.UserLogBrowseMapper;
import com.fxp.project.jiuselu.web.models.userlog.service.IUserLogBrowseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 浏览足迹Service业务层处理
 *
 * @author Jason.Wang
 * @date 2022-08-12
 */
@Service
public class UserLogBrowseServiceImpl extends ServiceImpl<UserLogBrowseMapper, UserLogBrowse> implements IUserLogBrowseService
{
    @Autowired
    private UserLogBrowseMapper userLogBrowseMapper;

    /**
     * 查询浏览足迹
     *
     * @param id 浏览足迹主键
     * @return 浏览足迹
     */
    @Override
    public UserLogBrowse selectUserLogBrowseById(Long id)
    {
        return userLogBrowseMapper.selectUserLogBrowseById(id);
    }

    /**
     * 查询浏览足迹列表
     *
     * @param userLogBrowse 浏览足迹
     * @return 浏览足迹
     */
    @Override
    public List<UserLogBrowse> selectUserLogBrowseList(UserLogBrowse userLogBrowse)
    {
        return userLogBrowseMapper.selectUserLogBrowseList(userLogBrowse);
    }

    /**
     * 新增浏览足迹
     *
     * @param userLogBrowse 浏览足迹
     * @return 结果
     */
    @Override
    public int insertUserLogBrowse(UserLogBrowse userLogBrowse)
    {
        userLogBrowse.setCreateTime(LocalDateTime.now());
        List<UserLogBrowse> userLogBrowses = userLogBrowseMapper.selectList(new QueryWrapper<UserLogBrowse>()
                .eq("user_log_id", userLogBrowse.getUserLogId()).eq("goods_id", userLogBrowse.getGoodsId()));
        if(userLogBrowses.size()==0){
            return userLogBrowseMapper.insertUserLogBrowse(userLogBrowse);
        }
        return 0;
    }

    /**
     * 修改浏览足迹
     *
     * @param userLogBrowse 浏览足迹
     * @return 结果
     */
    @Override
    public int updateUserLogBrowse(UserLogBrowse userLogBrowse)
    {
        return userLogBrowseMapper.updateUserLogBrowse(userLogBrowse);
    }

    /**
     * 批量删除浏览足迹
     *
     * @param ids 需要删除的浏览足迹主键
     * @return 结果
     */
    @Override
    public int deleteUserLogBrowseByIds(Long[] ids)
    {
        return userLogBrowseMapper.deleteUserLogBrowseByIds(ids);
    }

    /**
     * 删除浏览足迹信息
     *
     * @param id 浏览足迹主键
     * @return 结果
     */
    @Override
    public int deleteUserLogBrowseById(Long id)
    {
        return userLogBrowseMapper.deleteUserLogBrowseById(id);
    }
}
